const INFO_KEY = 'hm_shopping_info'
const HISTORY_KEY = 'historyList'
const DEFAULT_ID = 'defaultId'

export const setUserInfo = (userInfo) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(userInfo))
}
export const getUserInfo = () => {
  const result = localStorage.getItem(INFO_KEY)
  return result ? JSON.parse(result) : { userId: '', token: '' }
}
export const removeUserInfo = () => {
  localStorage.removeItem(INFO_KEY)
}

export const setHistoryList = (historyList) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(historyList))
}
export const getHistoryList = () => {
  const result = localStorage.getItem(HISTORY_KEY)
  return result ? JSON.parse(result) : []
}
export const setDefaultId = (id) => {
  localStorage.setItem(DEFAULT_ID, JSON.stringify(id))
}
export const getDefaultId = () => {
  const result = localStorage.getItem(DEFAULT_ID)
  return result ? JSON.parse(result) : 0
}
